1.Backgroud
We need to use lighttpd as webserver to servive two web page:
- FastCGI (python bottle web micro framework)
- LUCI (openwrt’s cgi-bin/luci, which is CGI)
2. Support LUCI
After we study OpenWrt wiki docs, we know how to make lighttpd support luci.
Two key steps:
- enable lighttpd’s “mod_cgi” module
- tell lighttpd all requests to “cgi-bin/luci” will send to lua, lighttpd ignore them
1 | # Ensure we have to enable mod_cgi, which is in conf.d |
Detail see OpenWrt Wiki about LuCI on lighttpd
3. Support FastCGI
The lighttpd fastcgi configuration like this:
1 | # Ensure mod_fastcgi mod_rewrite have been enabled, some modules will be enabled |
3.1. fcgi server
We need to tell lighttpd:
- “bin-path” : where lighttpd will startup executable file
- “socket” : fast cgi use socket send/receive msg
- “check-local” : Whether check file is existed in “server.document-root”
- “max-procs” : lighttpd support multiple process (optional)
Lighttpd docs about FastCGI http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI
3.2. URL Redirect
Because lighttpd support two web pages, we need to do something make url access ok.
3.2.1. Bottle Python Redirect
If fastcgi server work well, we need to add “/python_entry”. For example, we access “172.28.52.152/home” should be “172.28.52.152/python_entry”. We use “mod_rewrite” module to avoid this embarrassed situation. This module will pre-process URL before we really access it.
3.2.2. LUCI Redirect
We need to keep luci access like “cgi-bin/luci” and “luci-static”(which is used for js, css, etc resource files). So we use:1
2
3
4
5
6
7# [Note]
# Python request will send to "/python_entry" + "$1", except:
# 1. document.domain + "/cgi-bin/luci"
# 2. document.domain + "/luci-static"
url.rewrite-once = (
"^(/(?!(cgi|luci-static)).*)" => "/python_entry" + "$1",
)
How to represent “except xxx” ?
In Reluar Expression, we use “?!“ to express except. So next regular expression is except begin with “cgi” or “luci-staic”.
^(/(?!(cgi|luci-static)).*)